{php include wl_template('common/header');}
<ul class="nav nav-tabs">
    <li><a href="{php echo web_url('headline/headline/infoList')}">头条信息</a></li>
    <li class="active"><a href="{php echo web_url('headline/headline/getIntoEdit')}">发布头条</a></li>
</ul>
<style>
    #formList .chosen-select{
        width: 49.75%;
        display: inline-block;
        margin: 0;
    }
</style>
<div class="app-content">
    <div class="app-form">
        <div class="panel panel-default">
            <form action="{php echo web_url('headline/headline/edit')}" class="form-horizontal form" method="post" onsubmit="return formcheck(this);">
                <div class="panel-heading">发布头条信息</div>
                <div class="panel-body" id="formList">

                    <div class="form-group">
                        <div class="col-sm-2 control-label must "><span class="text-danger">*</span>头条标题</div>
                        <div class="col-sm-9">
                            <input class="form-control" type="text" maxlength="60" name="data[title]" value="{$info['title']}" placeholder="请输入头条标题" />
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-2 control-label must "><span class="text-danger">*</span>封面图片</div>
                        <div class="col-sm-9">
                            {php echo attachment_select('data[display_img]',$info['display_img']);}
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-2 control-label must ">幻灯片</div>
                        <div class="col-sm-9">
                            <div id="datas">
                                {loop $advs $key $ad}
                                {php include wl_template('headline/advurl');}
                                {/loop}
                            </div>
                            <span class="help-block">不设置任何幻灯片则会在文章头条顶部显示封面图片。</span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"></label>
                        <div class="col-sm-9">
                            <a class="btn btn-info btn-add-type" href="javascript:;" onclick="addType();">
                                <i class="fa fa-plus" title=""></i>增加一张幻灯片
                            </a>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-2 control-label must "><span class="text-danger">*</span>头条简介</div>
                        <div class="col-sm-9">
                            <input class="form-control" type="text" name="data[summary]" value="{$info['summary']}" placeholder="请输入头条简介" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label must"><span class="text-danger">*</span>选择分类</label>
                        <div class="col-sm-5">
                            <select name="data[one_id]" id="oneID" class="form-control chosen-select">
                                <option value="">请选择一级分类</option>
                                {loop $classList $k $v}
                                    <option value="{$v['id']}" {if $v['id'] == $info['one_id']}selected{/if}>{$v['name']}</option>
                                {/loop}
                            </select>
                        </div>
                        <div class="col-sm-5">
                            <select name="data[two_id]" id="twoID" class="form-control chosen-select">
                                <option value="">请选择二级分类</option>
                                {loop $subClass $k $v}
                                    <option value="{$v['id']}" {if $v['id'] == $info['two_id']}selected{/if}>{$v['name']}</option>
                                {/loop}
                            </select>
                        </div>
                    </div>
                    <!--<div class="form-group">-->
                        <!--<div class="col-sm-2 control-label must ">头条标签</div>-->
                        <!--<div class="col-sm-9">-->
                            <!--<input class="form-control" type="text" maxlength="100" name="data[labels]" value="{$info['labels']}" placeholder="请输入头条标签（多个标签使用#号隔开）" />-->
                        <!--</div>-->
                    <!--</div>-->
                    <div class="form-group">
                        <div class="col-sm-2 control-label must "><span class="text-danger">*</span>具体内容</div>
                        <div class="col-sm-9">
                            {php echo tpl_diy_editor_create('data[content]',$info['content']);}
                        </div>
                    </div>
                    <div class="form-group-title">其他信息</div>
                    <div class="form-group">
                        <div class="col-sm-2 control-label must "><span class="text-danger">*</span>作者昵称</div>
                        <div class="col-sm-9">
                            <input class="form-control" type="text" maxlength="15" name="data[author]" value="{$info['author']}" placeholder="请输入作者昵称" />
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-2 control-label must"><span class="text-danger">*</span>作者头像</div>
                        <div class="col-sm-9">
                            {php echo attachment_select('data[author_img]',$info['author_img']);}
                        </div>
                    </div>
                    <div class="form-group" id="goods">
                        <label class="col-sm-2 control-label must">推荐商品</label>
                        <div class="col-sm-9 is_judge" is_judge="false">
                            {php echo tpl_select_goods($info);}
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-2 control-label must ">浏览量</div>
                        <div class="col-sm-9">
                            <input class="form-control is_judge" is_judge="false" type="number" name="data[browse]" value="{$info['browse']}" placeholder="请输入初始浏览量" />
                        </div>
                    </div>
                    {if p('wxapp')}
                    <div class="form-group">
                        <div class="col-sm-2 control-label">流量主banner广告ID</div>
                        <div class="col-sm-9">
                            <input class="form-control is_judge" is_judge="false" type="text" name="data[bannerid]" value="{$info['bannerid']}" placeholder="请输入流量主banner广告ID" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">广告位置</label>
                        <div class="col-sm-9">
                            <label class="radio-inline"><input type="radio" name="data[banposition]" value="1" {if $info['banposition']==1 || empty($info['banposition']) }checked="checked"{/if}> 顶部</label>
                            <label class="radio-inline"><input type="radio" name="data[banposition]" value="2" {if $info['banposition']==2}checked="checked"{/if}> 中间</label>
                            <label class="radio-inline"><input type="radio" name="data[banposition]" value="3" {if $info['banposition']==3}checked="checked"{/if}> 底部</label>
                        </div>
                    </div>
                    {/if}


                </div>
                <div class="form-group">
                    <div class="col-sm-2 control-label must "></div>
                    <div class="col-sm-9">
                        <input type="hidden" name="id" value="{$info['id']}" />
                        <input type="submit" name="submit" value="提交" class="btn btn-primary col-sm-1 min-width" />
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    let two_id = "{php echo $info['two_id']}";
    //提交信息进行判断
    function formcheck() {
        //循环判断
        var state = true
            ,val
            ,tips;
        $("#formList input").each(function () {
            val = $(this).val();
            var is_judge = $(this).closest(".is_judge").attr("is_judge");
            if(is_judge != 'false'){
                if(val == ''){
                    tips = ($(this).attr("placeholder"))?($(this).attr("placeholder")):'请上传图片';
                    state = false;
                    return false;
                }
            }
        });
        //判断文本域是否有内容
        var ue  = UE.getEditor('data[content]');
        var content = ue.getContent();
        if(state == true && content == ''){
            tips  = '请填写具体内容!';
            state = false;
        }
        //判断是否选择分类信息
        if(state == true && $("#oneID").val() == ''){
            tips  = '请选择分类信息!';
            state = false;
        }
        if(tips){
            tip.msgbox.err(tips);
        }
        return state;
    }
    /**
     * 分类二级联动
     * @type {Array}
     */
    $("#oneID").on("change", function () {
        //删除现有的二级分类信息
        $("#twoID option:gt(0)").remove();
        //获取参数信息
        var id = $(this).val(),
            list = [],
            html = '';
        //请求后台获取下级菜单
        if(id > 0){
            $.post("{php echo web_url('headline/headline/getSubClass')}",{id:id}, function(data){
                list = data['data'];
                //根据内容生成html
                if (list) {
                    $.each(list, function (k, v) {
                        if(v['id'] == two_id){
                            html += "<option value='" + v['id'] + "' selected>" + v['name'] + "</option>";
                        }else{
                            html += "<option value='" + v['id'] + "'  >" + v['name'] + "</option>";
                        }
                    });
                }
                //加载新的内容信息
                $("#twoID").append(html);
            }, 'json');
        }
    });

    var kw = 1;
    function addType() {
        $(".btn-add-type").button("loading");
        $.ajax({
            url: "{php echo web_url('headline/headline/advurl')}&kw="+kw,
            cache: false
        }).done(function (html) {
            $(".btn-add-type").button("reset");
            $("#datas").append(html);
        });
        kw++;
    }
    $(".form").on('click','.clearinput',function () {
        $(this).prev().prev().val('');
    });
    function removes(asd){
        $(asd).closest('.data-item').remove();
    }

</script>
{php include wl_template('common/footer');}
